package cc.linker.steplink.crm.merchanth5.service.acs;

import cc.linker.steplink.crm.commons.coupon.CouponCustomerInfo;
import cc.linker.steplink.crm.merchanth5.pojo.*;
import cc.linker.steplink.crm.merchanth5.pojo.acs.AccountInfo;
import cc.linker.steplink.crm.response.GlobalException;

import java.io.UnsupportedEncodingException;
import java.util.*;

public interface PurchaseProcessService {

    /**
     * 确认订单
     */
    // CheckMerchantOrderPo checkOrder(Map<String, Object> param);

    Map<String, Object> getCustomerInfoByCustomerId(String customerId);

    /**
     * 创建订单
     */
    Map createOrder(Map<String, Object> param) throws GlobalException, UnsupportedEncodingException;

    Map payOrderByxcx(Map<String, Object> param);

    /**
     * 订单支付回调
     */
    void payCallback(Map<String, Object> param) throws Exception;

    /**
     * 计算反润金额
     *
     * @param sysAmount
     * @param cutPercent
     * @return
     */
    Integer getCutMoney(Integer sysAmount, String cutPercent);

    /**
     * 调用结果处理(中金)
     */
    String callResultProcess(String result) throws GlobalException;

    /**
     * 调用结果处理(微信)
     */
    String callResultProcessWx(String result) throws GlobalException;

    /**
     * 根据用户id判断是否为普通用户(需要分金币的用户)
     */
    boolean getUserRole(String customerId);

    /**
     * 生成业务单号
     * 前缀+13位时间戳+用户id
     */
    String generateBusiSn(Integer tradeType, String customerId);

    void buyGoodsSmsPush(List<Map<String, Object>> goodsIdAndBuyNum, String orgId);

    /**
     * 根据机构和费用类型查询分账配置账号
     *
     * @param type  见FeeConstants
     * @param orgId 机构id
     */
    String getAccountNumByFeeTypeAndOrdId(String type, String orgId) throws GlobalException;

    /**
     * 根据机构和费用类型查询分账配置账号id
     *
     * @param type  见FeeConstants
     * @param orgId 机构id
     */
    String getCustomerIdByFeeTypeAndOrdId(String type, String orgId, Integer payMode) throws GlobalException;

    /**
     * 根据费用类型，获得账户类型ABC
     *
     * @param type
     * @param orgId
     * @return
     */
    String getAccountTypeByFeeTypeAndOrgId(String type, String orgId);

    /**
     * 生成account数据
     *
     * @param name
     * @param amount
     * @param orgId
     * @return
     * @throws GlobalException
     */
    AccountInfo getAccountMap(String name, Integer amount, String orgId, Integer payMode) throws GlobalException;

    /**
     * 生成微信支付调用参数
     */
    Map<String, Object> getWxPayParam(String openId, String orderSn, String totalFee, String orgId, boolean needShare);

    String getCustomerIdByTokenAndOpenid(Map<String, Object> param);

    void payCallBackForWx(Map<String, Object> param) throws Exception;

    void setTemplateMessageList(Map data);

    /**
     * 根据orderSn 进行金额下发
     *
     * @param orderSn
     */
    void signalAgentPay(String orderSn, String orgid);

    void signalAgentPayAll(String alias, String sn);

    void signalAgentPayPart(String alias, String sn, String paySn, String orgId, Integer payMode);

    Map getSplitItems(String orderSn, String orgId, Integer payMode);

    void openAccountsByOrgId(String orgId);

    Map<String, Object> checkKnowledgeOrder(Map<String, Object> param);

    /**
     * 微信退款
     *
     * @param orderSn   订单sn
     * @param reason    退款原因
     * @param refundFee 退款金额(单位分，不得大于订单总金额)
     * @return 退款单号和退款id
     */
    Map<String, String> refund(String orderSn, String reason, Integer refundFee, String PaySn);

    /**
     * 生成微信退款调用参数
     */
    Map<String, Object> getWxRefundParam(String orgId, String orderSn, String transactionId, String reason, String totalFee, String refundFee);

    /**
     * 微信退款查询
     *
     * @param orderSn     订单sn
     * @param outRefundNo 退款单号
     * @param refundId    退款Id
     * @return 退款状态： SUCCESS—退款成功 REFUNDCLOSE—退款关闭。 PROCESSING—退款处理中 CHANGE—退款异常
     */
    String refundQuery(String orderSn, String outRefundNo, String refundId);

    /**
     * 生成微信退款查询调用参数
     */
    Map<String, Object> getWxRefundQueryParam(String orgId, String orderSn, String outRefundNo, String refundId, String transactionId);

    /**
     * 通联转账退款回调
     */
    void transferRefundCallBack(Map<String, Object> param);

    /**
     * 通联退款回调
     */
    void refundCallBack(Map<String, Object> param);

    /**
     * 通过机构id获取解冻时间
     */
    String getUnfreezeTimeByOrgId(String orgId);

    /**
     * 更新状态
     */
    void updateProtectStatusWhereAutoConfirm(String orderSn, String unfreezeTime);

    /**
     * 判断订单是否在退款中
     *
     * @param orderSn
     * @return true-在退款中，false-不在退款中
     */
    boolean judgeOrderIfInRefundByOrderSn(String orderSn);

    //退款到账发送短信
    void sendMsg(String orgId, String phone, String businessType, String orderSn);

    void exercise(Map<String, Object> map);

    /**
     * 新确认订单
     */
    List<CheckMerchantOrderPo> checkOrderNew(Map<String, Object> param, CouponCustomerInfo couponCustomerInfo);

    String getOrgIdByToken(Map<String, Object> param);

    String getCustomerIdByOrgIdAndOpenid(Map<String, Object> param);

    //获取订单支付状态
    Map<String, Object> getOrderPayStatus(String orderSn, String payType);

    //计算运费
    Map<String, Object> getGoodsShippingFee(Integer addressId, Integer goodsId, Integer buyCount);

    //供货商商品减库存
    Integer saveMallsGoodsCount(Long goodsId, String skuId, Integer goodsNum, Long mallsGoodsId, Long mallsSkuId);

    String getUniquePrimaryKey();
}